package com.jilian.powerstation.modul.activity;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;
import android.util.Log;

import com.jilian.powerstation.MyApplication;
import com.jilian.powerstation.base.BaseMainActivity;
import com.jilian.powerstation.common.dto.PowerDto;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MainActivity extends BaseMainActivity {
    private PowerDto data;

    public PowerDto getData() {
        return data;
    }

    public void setData(PowerDto data) {
        this.data = data;
    }

    @Override
    protected void createViewModel() {
    }


    @Override
    protected void init() {
        data = (PowerDto) getIntent().getSerializableExtra("data");
        getCode();

    }

    @Override
    protected void onStart() {
        super.onStart();
        MyApplication.clearSpecifyActivities(new Class[]{WelcomeActivity.class});
    }

    private void getCode() {
        try {
            int i = 0;
            PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                i++;
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String KeyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
                //KeyHash 就是你要的，不用改任何代码  复制粘贴 ;
                Log.e("=========", KeyHash);
            }
        } catch (
                PackageManager.NameNotFoundException e) {

        } catch (
                NoSuchAlgorithmException e) {

        }
    }


}
